package com.mk.admin.service.impl;

import com.mk.admin.mapper.*;
import com.mk.admin.model.*;
import com.mk.admin.model.entity.*;
import com.mk.admin.model.vo.*;
import com.mk.admin.service.*;
import com.mk.admin.util.*;
import org.springframework.beans.factory.annotation.*;
import org.springframework.data.redis.core.*;
import org.springframework.stereotype.*;

import java.util.*;

@Service
public class OrderTemplateServiceImpl implements OrderTemplateService {
    @Autowired
    private OrderTemplateMapper orderTemplateMapper;
    @Autowired
    private RedisTemplate redisTemplate;
    @Override
    public ResultDto select(TemplateVo vo) {
        OrderTemplateEntity entity = JSONCopy.copy(vo, OrderTemplateEntity.class);
        return ResultDto.data(orderTemplateMapper.select(entity));
    }

    @Override
    public ResultDto add(TemplateVo vo) {

        String userId= (String) redisTemplate.opsForValue().get("username");
        vo.setCreateTime(DateTool.format());
        vo.setStatus(1);
        vo.setCreator( userId);
        return ResultDto.data(orderTemplateMapper.insert(JSONCopy.copy(vo, OrderTemplateEntity.class)));
    }
    @Override
    public ResultDto delete(int id) {
        return ResultDto.data(orderTemplateMapper.deleteById(id));
    }

    @Override
    public ResultDto update(TemplateVo vo) {
       vo.setSort(vo.getSort());
       vo.setId(vo.getId());
        return ResultDto.data(orderTemplateMapper.updateById(JSONCopy.copy(vo, OrderTemplateEntity.class)));
    }

}
